//园区 - 商家
import { BasicMarker } from '../../js/BasicMarker.js';
import { BasicMarkers } from '../../js/BasicMarkers.js';
import { getMarkerIcon } from '../../js/icon.js';
import { useUserInfoStore } from '@gis/lib/pinia/userInfo.js';
import { handleCommonRes } from '@gis/lib/utils/resolver.js';
import { getEnterprisePrickPoint } from '@gis/lib/api';

import { netAndScenicDataStore } from '@gis/lib/pinia/netAndScenic.js';
import { dialog } from '@gis/lib/components/antd-dialog';
import { openShopDetailsDialog } from '../../../../views/shop/opt.js';

class Marker extends BasicMarker {
  constructor({ map, data }) {
    super({ map, data });
    /* this.type: 这个type主要用于筛选,需要和filter-legend里面的type相对应 */
    this.type = 'cyshangjia';
    super.create();
  }
  getIcon() {
    return getMarkerIcon(this.type);
  }
  getTitle() {
    return this.data.subject_name;
  }
  getIconOption(icon) {
    return {
      content: `<div style="width: 52px;height: 96px;background: url(${icon}) center center no-repeat;background-size: 100% 100%"></div>`,
      offset: new AMap.Pixel(0, 0),
    };
  }
  onClick() {
    openShopDetailsDialog(this.data);
  }
}

export default class Cyshangjia extends BasicMarkers {
  constructor({ map }) {
    super();
    this.map = map;
  }
  createMarker(data) {
    return new Marker({ map: this.map, data });
  }
  async getDataAsync() {
    const { area_code } = useUserInfoStore();
    const { scenicIds } = netAndScenicDataStore();
    console.log(area_code, scenicIds, '值111');
    const params = {
      area_code: scenicIds ? scenicIds : area_code,
    };
    const data = await handleCommonRes(getEnterprisePrickPoint, params);
    return data.map((item) =>
      Object.assign(item, {
        lnglat: [item.longitude, item.latitude],
        around_p_type_name: item.around_p_type_name ? item.around_p_type_name : '餐饮美食', //没有值，默认餐饮美食
      })
    );
  }
}
